how to reverse the string with preserving the position of spaces in java